<template>
    <div class="save-com-wrapper  " :class="{'ui segment loading':loading}">
        <component v-if="loaded" :is='components_name' :isAdd='isAdd'></component>
        <p v-else>loading</p>
    </div>
</template>
<script>
import myattr from 'components/edit/attr'
import mymenu from 'components/edit/menu'
import mymodel from 'components/edit/model'
import mbind from 'components/edit/mbind'
import mbindEdit from 'components/edit/mbind_edit'
import editCom from 'components/edit/editCom'
import ProductType from 'components/edit/ProductType'
import Product from 'components/edit/Product'
import TopProduct from 'components/edit/TopProduct'
import Bindconf from 'components/edit/Bindconf'
import ServiceCharge from 'components/edit/ServiceCharge'
import Qd from 'components/edit/Qd'

import addWarehousePro from 'components/edit/addWarehousePro'

import tool from 'src/util/tool';
import util from '_util/index';

export default {
    methods: {
        setSaveLoading(val) {
            this.loading = val
        },
        afterAdd(_this) {
            let eventVue = util.store.get(this,'eventVue');

            if (this.$store.state.global.op != 'update') {
                util.store.commit(this,'setEditVo', {})
                $(".ui.dropdown").dropdown("restore defaults");

                eventVue.$emit('clearTable')
                eventVue.$emit('refreshData')


            }

            switch (this.$store.state.global.current_ctl) {
                case 'Menu':
                    if (_this)
                        _this.vo = {}
                    eventVue.$emit('upSysInfo')
                    break;
            }

        },
    },
    watch: {
        loaded: function(val) {
            this.loading = !this.loaded
        }
    },
    data() {
        return {
            loading: true
        }
    },
    computed: {
        components_name() {
            let str = ''
            switch (this.ctl) {
                case 'Mbind_edit':
                    str = 'mbindEdit';
                    break;
                case 'Attr':
                    str = 'myattr';
                    break;
                case 'Menu':
                    str = 'mymenu';
                    break;
                case 'Mbind':
                    str = 'mbind';
                    break;
                case 'Model':
                    str = 'mymodel';
                    break;
                case 'ProductType':
                    str = 'ProductType';
                    break;
                case 'TopProduct':
                    str = 'TopProduct';
                    break;
                case 'Product':
                    str = 'Product';
                    break;
                case 'Bindconf':
                    str = 'Bindconf';
                    break;
				case 'addWarehousePro':
					str = 'addWarehousePro';
					break;
				case 'ServiceCharge':
					str = 'ServiceCharge';
					break;
				case 'Qd':
					str = 'Qd';
					break;
                default:
                    str = 'editCom'
            }
            return str;
        },
        ctl() {
            let ctl = this.$route.query.ctl
            if (ctl == 'Mbind') {
                ctl = this.$store.state.global.op == 'update' ? 'Mbind_edit' : ctl;
            }
            return ctl;
        },
        isAdd() {
            return util.getOp(this) == 'insert';
        },
    },
    components: {
        myattr,
        mymenu,
        mymodel,
        mbindEdit,
        editCom,
        ProductType,
        TopProduct,
        Bindconf,
        Product,
        mbind,
        addWarehousePro,
		ServiceCharge,
		Qd
    },
    props: ['loaded'],
    created() {
        this.loading = !this.loaded
        // this.loading=false;

        util.setCtlinfo(this);

        let eventVue = util.store.get(this,'eventVue');
        eventVue.$on('afterAdd', this.afterAdd)
        eventVue.$on('setSaveLoading', this.setSaveLoading)

    }
}
</script>
<style rel="stylesheet/less" lang="less">@dir: "common/";</style>
